Use the field-based PermutedDims to align permuted broadcasts#201
Merged
Conversation
## Summary Aligns a misaligned operand in named-tensor addition with `TensorAlgebra.PermutedDims` instead of `Base.PermutedDimsArray`. `PermutedDimsArray` encodes the permutation in a type parameter, so a runtime permutation forces a type-unstable, allocating construction on every permuted add. `PermutedDims` stores the permutation in a field, builds cheaply and type-stably, and is a broadcast leaf the linear-combination fold absorbs, so a permuted add no longer pays that type-construction floor and closes most of the gap to an aligned add. Builds on the broadcast-friendly `PermutedDims` from ITensor/TensorAlgebra.jl#198.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #201 +/- ##
==========================================
+ Coverage 74.00% 74.03% +0.03%
==========================================
Files 28 28
Lines 1500 1502 +2
==========================================
+ Hits 1110 1112 +2
Misses 390 390
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The public `unnamed(a, names)` keeps returning a `Base.PermutedDimsArray` (a full array), so callers outside broadcasting are unaffected. Only `broadcasted_unnamed` aligns a misaligned operand with `TensorAlgebra.PermutedDims`, whose minimal array interface stays confined to the broadcast hot path and is never handed to users. Also removes the `[sources]` pin now that TensorAlgebra 0.15.1 is registered, and switches a GPU-unsafe `dot` test to eager `unname`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Aligns a misaligned operand in named-tensor broadcasting with
TensorAlgebra.PermutedDimsinstead ofBase.PermutedDimsArray.PermutedDimsArrayencodes the permutation in a type parameter, so a runtime permutation forces a type-unstable, allocating construction on every permuted add.PermutedDimsstores the permutation in a field, builds cheaply and type-stably, and is a broadcast leaf the linear-combination fold absorbs viabipermutedimsopadd!, so a permuted add no longer pays that type-construction floor and closes most of the gap to an aligned add. The wrapper stays confined to the broadcast alignment path (broadcasted_unnamed) and is never returned by the publicunnamed(a, names).Builds on the broadcast-friendly
PermutedDimsfrom ITensor/TensorAlgebra.jl#198.